package uk.ac.bath.machines.tristate;

import uk.ac.bath.legacy.Operator;
import uk.ac.bath.legacy.VectorState;
import java.io.*;

public class Diff extends Operator {

    double last;

    public void tick(VectorState in, VectorState out) {
        double nxt = in.at(1).val;
        out.at(0).set((nxt - last)/2.0);
        last = nxt;
    //    throw new UnsupportedOperationException("Not supported yet.");
    }

    public void tick(VectorState in, VectorState out, int map[]) {
        double nxt = in.v[map[1]].val;
        out.v[map[0]].set((nxt - last)/2);
        last = nxt;
    }

    public int getStateSize() {
        return 2;
    }

    public int getParamSize() {
        return 2;
    }

    public Object clone() {
        return new Diff();   // this has state
    }

    public void toString(StringWriter w) {
        w.write("Diff ");
    }
}
